/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package View.maestros;

import Model.Empleado;
import View.components.Index;
import Model.Perfil;
import Presenter.EmpleadoPresenter;
import Presenter.EnvioPedidoPresenter;
import Presenter.PerfilPresenter;
import Principals.Utils;
import Principals.Validadores;
import java.awt.Component;
import java.awt.Event;
import java.awt.event.KeyEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.InputMap;
import javax.swing.JComponent;
import javax.swing.JDesktopPane;
import javax.swing.JOptionPane;
import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author walter
 */
public class Frm_BuscarEmpleado extends javax.swing.JDesktopPane {

    private DefaultTableModel mdlBuscarEmpleado;
    /**
     * Creates new form Frm_BuscarEmpleado
     */
    Validadores val = new Validadores();

    public Frm_BuscarEmpleado() {
        initComponents();
        EnvioPedidoPresenter.actualizarEnvioPedido();

        val.desactivarAccionPegar(txtApellidoMaterno);
        val.desactivarAccionPegar(txtApellidoPaterno);
        val.desactivarAccionPegar(txtNombre);
        val.desactivarAccionPegar(txtNroDocId);
        tblBuscarEmpleado.getTableHeader().setReorderingAllowed(false);
        mdlBuscarEmpleado = new DefaultTableModel();
        // Combo de perfiles
        cbxPerfil.addItem("Todos");
        List<Perfil> lstPerfil = PerfilPresenter.listPerfil();
        for (Perfil p : lstPerfil) {
            cbxPerfil.addItem(p);
        }
        //Combo estado
        String[] lstEstados = Utils.getEstadosEmpleado();
        cbxEstado.addItem("Todos");
        for (int i = 1; i < lstEstados.length; i++) {
            cbxEstado.addItem(lstEstados[i]);
        }
        if (cbxPerfil.getSelectedItem().toString().equals("Conductor")) {
            //cbxEstado.setEnabled(true);
            //lblEstado.setEnabled(true);
            cbxEstado.setVisible(true);
            lblEstado.setVisible(true);
        } else {
            //cbxEstado.setEnabled(false);
            //lblEstado.setEnabled(false);
            cbxEstado.setVisible(false);
            lblEstado.setVisible(false);
        }

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jToolBar2 = new javax.swing.JToolBar();
        btnToolNuevo = new javax.swing.JButton();
        btnToolModificar = new javax.swing.JButton();
        btnToolAlmacenar = new javax.swing.JButton();
        btnToolEliminar = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        btnToolLimpar = new javax.swing.JButton();
        btnToolBuscar = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        btnToolCancelar = new javax.swing.JButton();
        pnlBuscarEmpleado = new javax.swing.JPanel();
        lblApellidoPaterno = new javax.swing.JLabel();
        txtApellidoPaterno = new javax.swing.JTextField();
        lblNombre = new javax.swing.JLabel();
        txtNombre = new javax.swing.JTextField();
        lblApellidoMaterno = new javax.swing.JLabel();
        txtApellidoMaterno = new javax.swing.JTextField();
        lblDocIdentidad = new javax.swing.JLabel();
        txtNroDocId = new javax.swing.JTextField();
        lblPerfil = new javax.swing.JLabel();
        cbxPerfil = new javax.swing.JComboBox();
        btnBuscar = new javax.swing.JToggleButton();
        lblEstado = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        cbxEstado = new javax.swing.JComboBox();
        pnlResultadosEmpleado = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tblBuscarEmpleado = new javax.swing.JTable();

        jToolBar2.setFloatable(false);
        jToolBar2.setBorderPainted(false);

        btnToolNuevo.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Nuevo.png"))); // NOI18N
        btnToolNuevo.setFocusable(false);
        btnToolNuevo.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolNuevo.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolNuevo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolNuevoActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolNuevo);

        btnToolModificar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Editar.png"))); // NOI18N
        btnToolModificar.setFocusable(false);
        btnToolModificar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolModificar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolModificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolModificarActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolModificar);

        btnToolAlmacenar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Guardar.png"))); // NOI18N
        btnToolAlmacenar.setEnabled(false);
        btnToolAlmacenar.setFocusable(false);
        btnToolAlmacenar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolAlmacenar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolAlmacenar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolAlmacenarActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolAlmacenar);

        btnToolEliminar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Eliminar.png"))); // NOI18N
        btnToolEliminar.setFocusable(false);
        btnToolEliminar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolEliminar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolEliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolEliminarActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolEliminar);
        jToolBar2.add(jSeparator3);

        btnToolLimpar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Limpiar.png"))); // NOI18N
        btnToolLimpar.setFocusable(false);
        btnToolLimpar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolLimpar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolLimpar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolLimparActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolLimpar);

        btnToolBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Buscar.png"))); // NOI18N
        btnToolBuscar.setEnabled(false);
        btnToolBuscar.setFocusable(false);
        btnToolBuscar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolBuscar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolBuscarActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolBuscar);
        jToolBar2.add(jSeparator4);

        btnToolCancelar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/Images/botones/Cancelar.png"))); // NOI18N
        btnToolCancelar.setToolTipText("");
        btnToolCancelar.setEnabled(false);
        btnToolCancelar.setFocusable(false);
        btnToolCancelar.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btnToolCancelar.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btnToolCancelar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnToolCancelarActionPerformed(evt);
            }
        });
        jToolBar2.add(btnToolCancelar);

        pnlBuscarEmpleado.setBorder(javax.swing.BorderFactory.createTitledBorder("Búsqueda"));

        lblApellidoPaterno.setText("Apellido Paterno:");

        txtApellidoPaterno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtApellidoPaternoKeyTyped(evt);
            }
        });

        lblNombre.setText("Nombre:");

        txtNombre.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNombreKeyTyped(evt);
            }
        });

        lblApellidoMaterno.setText("Apellido Materno:");

        txtApellidoMaterno.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txtApellidoMaternoActionPerformed(evt);
            }
        });
        txtApellidoMaterno.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtApellidoMaternoKeyTyped(evt);
            }
        });

        lblDocIdentidad.setText("Doc. de Identidad*:");

        txtNroDocId.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyTyped(java.awt.event.KeyEvent evt) {
                txtNroDocIdKeyTyped(evt);
            }
        });

        lblPerfil.setText("Perfil");

        cbxPerfil.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbxPerfilActionPerformed(evt);
            }
        });

        btnBuscar.setText("Buscar");
        btnBuscar.setAutoscrolls(true);
        btnBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscarActionPerformed(evt);
            }
        });

        lblEstado.setText("Estado:");

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        javax.swing.GroupLayout pnlBuscarEmpleadoLayout = new javax.swing.GroupLayout(pnlBuscarEmpleado);
        pnlBuscarEmpleado.setLayout(pnlBuscarEmpleadoLayout);
        pnlBuscarEmpleadoLayout.setHorizontalGroup(
            pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblNombre)
                    .addComponent(lblApellidoPaterno)
                    .addComponent(lblApellidoMaterno))
                .addGap(18, 18, 18)
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addComponent(txtApellidoMaterno)
                    .addComponent(txtNombre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
                    .addComponent(txtApellidoPaterno, javax.swing.GroupLayout.Alignment.LEADING))
                .addGap(79, 79, 79)
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblDocIdentidad)
                    .addComponent(lblPerfil)
                    .addComponent(lblEstado))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                        .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(cbxPerfil, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(txtNroDocId)
                            .addComponent(cbxEstado, javax.swing.GroupLayout.Alignment.TRAILING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(15, 15, 15))
                    .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                        .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBuscarEmpleadoLayout.createSequentialGroup()
                .addContainerGap(276, Short.MAX_VALUE)
                .addComponent(btnBuscar)
                .addGap(269, 269, 269))
        );
        pnlBuscarEmpleadoLayout.setVerticalGroup(
            pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pnlBuscarEmpleadoLayout.createSequentialGroup()
                        .addGap(38, 38, 38)
                        .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(lblApellidoMaterno)
                            .addComponent(txtApellidoMaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(cbxPerfil, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblPerfil)))
                    .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(lblApellidoPaterno)
                        .addComponent(txtApellidoPaterno, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(txtNroDocId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(lblDocIdentidad)
                    .addComponent(jComboBox1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(pnlBuscarEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblNombre)
                    .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblEstado)
                    .addComponent(cbxEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 29, Short.MAX_VALUE)
                .addComponent(btnBuscar))
        );

        pnlResultadosEmpleado.setBorder(javax.swing.BorderFactory.createTitledBorder("Resultados"));

        tblBuscarEmpleado.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "ID", "Nombre", "Ap. Paterno", "Ap. Materno", "DNI", "Perfil", "Estado"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jScrollPane1.setViewportView(tblBuscarEmpleado);
        tblBuscarEmpleado.getColumnModel().getColumn(0).setResizable(false);
        tblBuscarEmpleado.getColumnModel().getColumn(1).setResizable(false);
        tblBuscarEmpleado.getColumnModel().getColumn(2).setResizable(false);

        javax.swing.GroupLayout pnlResultadosEmpleadoLayout = new javax.swing.GroupLayout(pnlResultadosEmpleado);
        pnlResultadosEmpleado.setLayout(pnlResultadosEmpleadoLayout);
        pnlResultadosEmpleadoLayout.setHorizontalGroup(
            pnlResultadosEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlResultadosEmpleadoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 590, Short.MAX_VALUE)
                .addContainerGap())
        );
        pnlResultadosEmpleadoLayout.setVerticalGroup(
            pnlResultadosEmpleadoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pnlResultadosEmpleadoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(pnlResultadosEmpleado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(pnlBuscarEmpleado, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jToolBar2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jToolBar2, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(pnlBuscarEmpleado, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(pnlResultadosEmpleado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void cambiarVista(JDesktopPane panel) {
        ((Index) (this.getTopLevelAncestor())).changeDesktopPane(panel);
    }

    private void btnToolNuevoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolNuevoActionPerformed
        cambiarVista(new Frm_RegistrarEmpleado()); // <---------------------------- ESTO SE DEBE CAMBIAR
    }//GEN-LAST:event_btnToolNuevoActionPerformed

    private void btnToolModificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolModificarActionPerformed
        int i = this.tblBuscarEmpleado.getSelectedRow();
        if (i != -1) {
            int idEmpleado = Integer.parseInt(this.tblBuscarEmpleado.getValueAt(i, 0).toString());
            cambiarVista(new Frm_ModificarEmpleado(idEmpleado));
        } else {
            JOptionPane.showMessageDialog(this, "No se ha seleccionado ningún vehículo.");
        }
    }//GEN-LAST:event_btnToolModificarActionPerformed

    private void btnToolBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolBuscarActionPerformed
    }//GEN-LAST:event_btnToolBuscarActionPerformed

    private void btnToolEliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolEliminarActionPerformed
        int i = this.tblBuscarEmpleado.getSelectedRow();
        if (i != -1) {
            int respuesta = JOptionPane.showConfirmDialog(this, "¿Desea eliminar este registro?", "Eliminar", JOptionPane.OK_CANCEL_OPTION);
            switch (respuesta) {
                case JOptionPane.OK_OPTION:
                    String est = this.tblBuscarEmpleado.getValueAt(i, 5).toString();
                    if (!est.equals("En ruta")) {
                        //Eliminar empleado
                        int idEmpleado = Integer.parseInt(this.tblBuscarEmpleado.getValueAt(i, 0).toString());
                        Empleado e = EmpleadoPresenter.cargarEmpleado(idEmpleado);
                        EmpleadoPresenter.eliminarEmpleado(e);

                        //Actualizar tabla de resultados
                        String ap = txtApellidoPaterno.getText();
                        String am = txtApellidoMaterno.getText();
                        String nomb = txtNombre.getText();
                        String dni = txtNroDocId.getText();
                        Perfil perfil = (Perfil) cbxPerfil.getSelectedItem();
                        int estado;
                        if (!cbxPerfil.getSelectedItem().toString().equals("Conductor")) {
                            estado=0;
                        } else {
                            estado = cbxEstado.getSelectedIndex();
                        }
                        List<Empleado> lstEmpleado = EmpleadoPresenter.buscarEmpleado(ap, am, nomb, dni, perfil,estado);
                        //JOptionPane.showMessageDialog(this, lstEmpleado.size());
                        mdlBuscarEmpleado.setNumRows(0);
                        mdlBuscarEmpleado = (DefaultTableModel) tblBuscarEmpleado.getModel();

                        for (int j = 0; j < lstEmpleado.size(); j++) {
                            Empleado e2 = lstEmpleado.get(j);
                            Object[] row = new Object[]{e2.getIdEmpleado(), e2.getNombres(), e2.getApellidoPaterno(), e2.getApellidoMaterno(),
                                e2.getNroDocumento(), e.getUsuario().getPerfil(),Utils.getEstadoEmpleado(e.getEstado())};
                            mdlBuscarEmpleado.insertRow(j, row);
                        }
                        tblBuscarEmpleado.setVisible(true);

                        JOptionPane.showMessageDialog(this, "Se elimininó el registro seleccionado.");
                    } else {
                        JOptionPane.showMessageDialog(this, "No se puede eliminar este empleado porque está en ruta.");
                    }
                    break;
                case JOptionPane.CANCEL_OPTION:
                    break;
            }
        } else {
            JOptionPane.showMessageDialog(this, "No se ha seleccionado ningún vehículo.");
        }
    }//GEN-LAST:event_btnToolEliminarActionPerformed

    private void btnToolCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolCancelarActionPerformed
        cambiarVista(new Frm_BuscarEmpleado());
    }//GEN-LAST:event_btnToolCancelarActionPerformed

    private void txtApellidoMaternoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txtApellidoMaternoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_txtApellidoMaternoActionPerformed

    private void btnToolAlmacenarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolAlmacenarActionPerformed
    }//GEN-LAST:event_btnToolAlmacenarActionPerformed

    private void btnBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscarActionPerformed

        String ap = txtApellidoPaterno.getText();
        String am = txtApellidoMaterno.getText();
        String nomb = txtNombre.getText();
        String dni = txtNroDocId.getText();
        int estado ;
        if (!cbxPerfil.getSelectedItem().toString().equals("Conductor")) {
            estado=0;
        } else {
            estado = cbxEstado.getSelectedIndex();
        }
        Perfil perfil;
        if (cbxPerfil.getSelectedItem().toString().equals("Todos")) {
            perfil = null;
            estado=0;
        } else {
            perfil = (Perfil) cbxPerfil.getSelectedItem();
        }
        List<Empleado> lstEmpleado = EmpleadoPresenter.buscarEmpleado(ap, am, nomb, dni, perfil, estado);
        //JOptionPane.showMessageDialog(this, lstEmpleado.size());
        mdlBuscarEmpleado.setNumRows(0);
        mdlBuscarEmpleado = (DefaultTableModel) tblBuscarEmpleado.getModel();

        for (int i = 0; i < lstEmpleado.size(); i++) {
            Empleado e = lstEmpleado.get(i);
            Object[] row = new Object[]{e.getIdEmpleado(), e.getNombres(), e.getApellidoPaterno(), e.getApellidoMaterno(),
                e.getNroDocumento(), e.getUsuario().getPerfil(),Utils.getEstadoEmpleado(e.getEstado())};
            mdlBuscarEmpleado.insertRow(i, row);
        }
        tblBuscarEmpleado.setVisible(true);

        //limpiar();
        JOptionPane.showMessageDialog(this, "Se encontró " + mdlBuscarEmpleado.getRowCount() + " conincidencia(s)");

    }//GEN-LAST:event_btnBuscarActionPerformed

    private void btnToolLimparActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnToolLimparActionPerformed
        txtApellidoMaterno.setText("");
        txtApellidoPaterno.setText("");
        txtNombre.setText("");
        txtNroDocId.setText("");
    }//GEN-LAST:event_btnToolLimparActionPerformed

    private void txtApellidoPaternoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApellidoPaternoKeyTyped
        val.validaCaracteresRaros(evt);
        val.validaMaxSize(evt, 50, txtApellidoPaterno.getText());
    }//GEN-LAST:event_txtApellidoPaternoKeyTyped

    private void txtApellidoMaternoKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtApellidoMaternoKeyTyped
        val.validaCaracteresRaros(evt);
        val.validaMaxSize(evt, 50, txtApellidoMaterno.getText());
    }//GEN-LAST:event_txtApellidoMaternoKeyTyped

    private void txtNombreKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNombreKeyTyped
        val.validaCaracteresRaros(evt);
        val.validaMaxSize(evt, 50, txtNombre.getText());
    }//GEN-LAST:event_txtNombreKeyTyped

    private void txtNroDocIdKeyTyped(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txtNroDocIdKeyTyped
        val.validaSoloNumeros(evt);
        val.validaMaxSize(evt, 8, txtNroDocId.getText());
    }//GEN-LAST:event_txtNroDocIdKeyTyped

    private void cbxPerfilActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbxPerfilActionPerformed
        if (cbxPerfil.getSelectedItem().toString().equals("Conductor")) {
            //cbxEstado.setEnabled(true);
            //lblEstado.setEnabled(true);
            cbxEstado.setVisible(true);
            lblEstado.setVisible(true);
        } else {
            //cbxEstado.setEnabled(false);
            //lblEstado.setEnabled(false);
            cbxEstado.setVisible(false);
            lblEstado.setVisible(false);
        }
    }//GEN-LAST:event_cbxPerfilActionPerformed
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JToggleButton btnBuscar;
    private javax.swing.JButton btnToolAlmacenar;
    private javax.swing.JButton btnToolBuscar;
    private javax.swing.JButton btnToolCancelar;
    private javax.swing.JButton btnToolEliminar;
    private javax.swing.JButton btnToolLimpar;
    private javax.swing.JButton btnToolModificar;
    private javax.swing.JButton btnToolNuevo;
    private javax.swing.JComboBox cbxEstado;
    private javax.swing.JComboBox cbxPerfil;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar jToolBar2;
    private javax.swing.JLabel lblApellidoMaterno;
    private javax.swing.JLabel lblApellidoPaterno;
    private javax.swing.JLabel lblDocIdentidad;
    private javax.swing.JLabel lblEstado;
    private javax.swing.JLabel lblNombre;
    private javax.swing.JLabel lblPerfil;
    private javax.swing.JPanel pnlBuscarEmpleado;
    private javax.swing.JPanel pnlResultadosEmpleado;
    private javax.swing.JTable tblBuscarEmpleado;
    private javax.swing.JTextField txtApellidoMaterno;
    private javax.swing.JTextField txtApellidoPaterno;
    private javax.swing.JTextField txtNombre;
    private javax.swing.JTextField txtNroDocId;
    // End of variables declaration//GEN-END:variables
}
